using System;

namespace Test.ConsoleProgram.Algorithm.Solution
{
    [TestDescription("算法: 1544. 整理字符串")]
    public class No1544_MakeGood : AbsBaseTestItem
    {
        public override void OnTest()
        {
            Assert.TestExe(MakeGood, "leEeetcode", "leetcode");
            Assert.TestExe(MakeGood, "abBAcC", "");
            Assert.TestExe(MakeGood, "s", "s");
        }

        public string MakeGood(string s)
        {
            if (string.IsNullOrEmpty(s)) return s;
            int i = 0;
            while (i <= s.Length - 1)
            {
                if (i < 0 || i >= s.Length)
                {
                    i++;
                    continue;
                }
                if (0 <= i && i <= s.Length - 2 && Math.Abs(s[i] - s[i + 1]) == 32)
                {
                    s = s.Remove(i, 2);
                    i--;
                    continue;
                }
                i++;
            }
            return s;
        }
    }
}
